//
//  SearchFileCell.m
//  KutulusLaw
//
//  Created by Mahmood1 on 12/11/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "SearchFileCell.h"

@implementation SearchFileCell
@synthesize delegate = _delegate;
@synthesize casesName;
@synthesize orderNumberLabel;
@synthesize postDateLabel;
@synthesize postTimeLabel;
@synthesize fileTypeImageButton;
@synthesize searchFileDTO = _searchFileDTO;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setSearchFileDTO:(KBaseSearchFileDTO *)searchFile {
	if (!searchFile) {
		return;
	}
	
	_searchFileDTO = searchFile;
		
	[self.casesName setText:[searchFile name]];
		
	NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
	dateFormatter.dateFormat = @"MM/dd/yyyy HH:mm:ss";
	
	NSDate *postDate = [dateFormatter dateFromString:searchFile.postDateText];
	
	dateFormatter.dateFormat = @"dd.MM.yyyy";
		
	[self.postDateLabel setText:[dateFormatter stringFromDate:postDate]];
		
	dateFormatter.dateFormat = @"HH:mm";
	[self.postTimeLabel setText:[dateFormatter stringFromDate:postDate]];
		
	if (searchFile.filePDF && [searchFile.filePDF length] > 0) {
		[self.fileTypeImageButton setHidden:NO];
		self.tag = eFileTypePDF;
	} else {
		[self.fileTypeImageButton setHidden:YES];
	}
}


- (IBAction)touchInsidePDFImageButton:(id)sender {
	if (self.delegate) {
		[self.delegate searchFileCell:self clickDocumentFile:self.fileTypeImageButton.tag relativePath:[self.searchFileDTO.filePDF copy]];
	}
}
@end
